package controller

import (
	"github.com/gin-gonic/contrib/sessions"
	"github.com/gin-gonic/gin"
	"net/http"
)

/**
 *@Author tudou
 *@Date 2019/8/24
 **/

func LoginState() gin.HandlerFunc{
	return func(context *gin.Context) {
		session:=sessions.Default(context)
		user:=session.Get("user")
		if user==nil{
			context.JSON(http.StatusOK,gin.H{"error":"please login "})
			context.Abort()
		}else{
			context.Next()
		}
	}
}

//func LimitHandler(lmt  *limiter.Limiter)gin.HandlerFunc{
//	return func(c *gin.Context){
//		httpError:=tollbooth.LimitByRequest(lmt,c.Writer,c.Request)
//		if httpError !=nil{
//			c.Data(httpError.StatusCode,lmt.GetMessageContentType(),[]byte(httpError.Message))
//			c.Abort()
//		}else{
//			c.Next()
//		}
//	}
//}